package com.ocn.li.scmdy.modules.sys.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ocn.li.scmdy.common.utils.QueryExt;
import com.ocn.li.scmdy.common.utils.R;
import com.ocn.li.scmdy.modules.app.entity.UserEntity;
import com.ocn.li.scmdy.modules.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * TODO 会员controller
 * 后台对app注册会员的管理
 *
 * @author crazypenguin
 * @version 1.0.0
 * @createdate 2019/1/2
 */
@RestController
@RequestMapping("/sys/member")
public class MemberController extends AbstractController {
	@Autowired
	private UserService userService;

	/**
	 * 会员分页列表
	 * @param params
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		params.put("orderByField","create_time");
		params.put("isAsc",false);
		Page page = userService.selectPageByConditions(new QueryExt<>(params));
		return R.ok().put("page", page);
	}

	/**
	 * 获取会员详情
	 * @return
	 */
	@GetMapping("/info/{userId}")
	public R info(@ApiParam(name = "userId", value = "用来获取会员详情的会员ID", required = true) @PathVariable("userId") int userId){
		UserEntity user = userService.selectById(userId);
		return R.ok().put("user", user);
	}


}
